<template>
  <div>
    <!-- 1. 先安装 axios npm install axios -->
    <!-- 2. 全局挂载axios -->
    <!-- 3. 可以使用 -->
    <el-table :data="tableData" style="width: 100%">
      <el-table-column prop="shopName" label="店铺名称" width="180">
      </el-table-column>
      <el-table-column prop="prodName" label="商品名称" width="180">
      </el-table-column>
      <el-table-column prop="pic" label="图片">
        <template slot-scope="scope">
          <img :src="scope.row.pic" width="45" alt="" />
        </template>
      </el-table-column>
      <el-table-column prop="brief" label="描述"> </el-table-column>
      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >详情</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <el-pagination
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :current-page="current"
      :page-sizes="[5, 20, 30, 50]"
      :page-size="size"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
    >
    </el-pagination>

    <el-dialog title="商品信息" :visible.sync="dialogVisible" width="70%">
      <el-descriptions title="用户信息">
        <el-descriptions-item label="商品名称">{{
          itemObj.prodName
        }}</el-descriptions-item>
        <el-descriptions-item label="手机号">18100000000</el-descriptions-item>
        <el-descriptions-item label="描述">{{
          itemObj.brief
        }}</el-descriptions-item>
        <el-descriptions-item label="图片">
          <img :src="itemObj.pic" alt="" />
        </el-descriptions-item>
        
      </el-descriptions>
      <div v-html="itemObj.content"></div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
export default {
  data() {
    return {
      current: 1, //页码
      total:0, //总条数
      size:5,

      tableData: [],
      dialogVisible: false, //控制模态框显示隐藏
      itemObj: {}, //存储详情
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /**
     * 切换每页条数
     */
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.size = val;
      this.getList()
    },
    /**
     * 点击页码
     */
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.current = val; //保存最新点击的页码
      this.getList() //根据最新页码 获取最新数据
    },

    // 查看商品详情
    handleEdit(i, a) {
      this.dialogVisible = true; //打开模态框
      this.$axios
        .get("http://api.app.yami.byesame.com/prod/prodInfo", {
          params: {
            prodId: a.prodId,
          },
        })
        .then((res) => {
          console.log(res);
          if (res.data.code == "00000") {
            this.itemObj = res.data.data;
          }
        });
    },
    // 请求参数
    // 页码 current 数字类型
    // 请求条数 size 数字类型

    // 查询商品详情
    // http://api.app.yami.byesame.com/prod/prodInfo
    // 请求参数
    // 商品id
    // prodId=要查寻的商品id
    getList() {
      this.$axios
        .get(
          "http://api.app.yami.byesame.com/prod/lastedProdPage?current="+this.current+"&size="+this.size
        )
        .then((res) => {
          console.log(res);
          if (res.data.code == "00000") {
            this.tableData = res.data.data.records;
            this.total = res.data.data.total;
          }
        });

      // let a = 'http://api.app.yami.byesame.com/prod/tag/prodTagList'
      //   this.$axios
      //     .get("http://api.app.yami.byesame.com/prod/tag/prodTagList")
      //     .then((res) => {
      //       console.log(res);
      //       if(res.data.code == '00000'){
      //         this.tableData = res.data.data
      //       }
      //     })
      //     .catch((err) => {
      //       console.log(err);
      //     });
    },
  },
};
</script>

<style>
</style>